﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using WarehouseManager.Core;
using WarehouseManager.Model;
namespace WarehouseManager.DataAccess
{
    class PhieunhapAccess
    {
        dbConnection db = new dbConnection();
        public DataTable layPN()
        {
            return db.executeSelectProcedureQueryNonParameter("selectPhieuNhap");
        }
        public DataView timkiemPhieunhaptheoma(string s)
        {
            DataView dataView = layPN().DefaultView;
            dataView.RowFilter = string.Format("maPN like %{0}%", s);
            return dataView;
        }
        public DataTable layPhieunhaptheoma(Phieunhap pn)
        {
            SqlParameter[] listParam = new SqlParameter[1];
            SqlParameter ma = new SqlParameter("@maPN", SqlDbType.Char, 10);
            ma.Value = pn.MaPN;
            listParam[0] = ma;
            return db.executeSelectProcedureQuery("tim_PN", listParam);
        }
        public int thempn(Phieunhap pn)
        {
            SqlParameter[] listParam = new SqlParameter[4];
            SqlParameter ma = new SqlParameter("@maPN", SqlDbType.VarChar, 10);
            ma.Value = pn.MaPN;
            listParam[0] = ma;
            listParam[1] = new SqlParameter("@maNCC", pn.MaNCC);
            listParam[2] = new SqlParameter("@ngayNhap", pn.NgayNhap);
            listParam[3] = new SqlParameter("@maNV", pn.MaNV);
            db.executeInsertProcedureQuery("insertPhieuNhap", listParam);
            return 1;
        }
        public int suapn(Phieunhap pn)
        {

            SqlParameter[] listParam = new SqlParameter[4];
            SqlParameter ma = new SqlParameter("@maPN", SqlDbType.VarChar, 10);
            ma.Value = pn.MaPN;
            listParam[0] = ma;
            listParam[1] = new SqlParameter("@maNCC", pn.MaNCC);
            listParam[2] = new SqlParameter("@ngayNhap", pn.NgayNhap);
            listParam[3] = new SqlParameter("@maNV", pn.MaNV);
            db.executeInsertProcedureQuery("updatePhieuNhap", listParam);
            return 1;
        }
        public int xoapn(Phieunhap pn)
        {
            
            SqlParameter[] listParam = new SqlParameter[4];
            SqlParameter ma = new SqlParameter("@maPN", SqlDbType.VarChar, 10);
            ma.Value = pn.MaPN;
            listParam[0] = ma;
            listParam[1] = new SqlParameter("@maNCC", pn.MaNCC);
            listParam[2] = new SqlParameter("@ngayNhap", pn.NgayNhap);
            listParam[3] = new SqlParameter("@maNV", pn.MaNV);
            db.executeInsertProcedureQuery("deletePhieuNhap", listParam);
            return 1;
        }

    }
}
